package cn.stylefeng.guns.modular.business.controller;

import cn.stylefeng.guns.modular.business.pojo.SubBookInfoRequest;
import cn.stylefeng.guns.modular.business.service.SubBookInfoService;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 控制器
 *
 * @author zhangyaowen
 * @date 2021/08/18 14:09
 */
@RestController
@ApiResource(name = "阅读数据管理")
public class SubBookInfoController {

    @Resource
    private SubBookInfoService subBookInfoService;

    /**
     * 添加
     *
     * @author zhangyaowen
     * @date 2021/08/18 14:09
     */
    @PostResource(name = "添加", path = "/subBookInfo/add")
    public ResponseData add(@RequestBody @Validated(SubBookInfoRequest.add.class) SubBookInfoRequest subBookInfoRequest) {
        subBookInfoService.add(subBookInfoRequest);
        return new SuccessResponseData();
    }

    /**
     * 删除
     *
     * @author zhangyaowen
     * @date 2021/08/18 14:09
     */
    @PostResource(name = "删除", path = "/subBookInfo/delete")
    public ResponseData delete(@RequestBody @Validated(SubBookInfoRequest.delete.class) SubBookInfoRequest subBookInfoRequest) {
        subBookInfoService.del(subBookInfoRequest);
        return new SuccessResponseData();
    }

    /**
     * 编辑
     *
     * @author zhangyaowen
     * @date 2021/08/18 14:09
     */
    @PostResource(name = "编辑", path = "/subBookInfo/edit")
    public ResponseData edit(@RequestBody @Validated(SubBookInfoRequest.edit.class) SubBookInfoRequest subBookInfoRequest) {
        subBookInfoService.edit(subBookInfoRequest);
        return new SuccessResponseData();
    }

    /**
     * 查看详情
     *
     * @author zhangyaowen
     * @date 2021/08/18 14:09
     */
    @GetResource(name = "查看详情", path = "/subBookInfo/detail")
    public ResponseData detail(@Validated(SubBookInfoRequest.detail.class) SubBookInfoRequest subBookInfoRequest) {
        return new SuccessResponseData(subBookInfoService.detail(subBookInfoRequest));
    }

    /**
     * 获取列表
     *
     * @author zhangyaowen
     * @date 2021/08/18 14:09
     */
    @GetResource(name = "获取列表", path = "/subBookInfo/list")
    public ResponseData list(SubBookInfoRequest subBookInfoRequest) {
        return new SuccessResponseData(subBookInfoService.findList(subBookInfoRequest));
    }

    /**
     * 获取列表（带分页）
     *
     * @author zhangyaowen
     * @date 2021/08/18 14:09
     */
    @GetResource(name = "分页查询", path = "/subBookInfo/page")
    public ResponseData page(String bookName,String chiefEditor,String bookPublish) {
        SubBookInfoRequest subBookInfoRequest = new SubBookInfoRequest();
        subBookInfoRequest.setBookName(bookName);
        subBookInfoRequest.setChiefEditor(chiefEditor);
        subBookInfoRequest.setBookPublish(bookPublish);
        return new SuccessResponseData(subBookInfoService.findPage(subBookInfoRequest));
    }

    /**
     * 获取推荐图书
     *
     * @author zhangyaowen
     * @date 2021/08/26 14:09
     */
    @GetResource(name = "图书推荐", path = "/subBookInfo/recommend")
    public ResponseData recommend() {
        SubBookInfoRequest subBookInfoRequest = new SubBookInfoRequest();
        subBookInfoRequest.setBookRecommend(1L);
        return new SuccessResponseData(subBookInfoService.recommendBook(subBookInfoRequest));
    }

    @GetResource(name = "详情", path = "/subBookInfo/toBookReview")
    public ResponseData toBookReview(String id) {
        return new SuccessResponseData(subBookInfoService.toSubBookInfoReview(id));
    }

}